package com.sxbbc.plat.controller.banks;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.api.R;
import com.sxbbc.common.basics.rest.RestResponse;
import com.sxbbc.common.basics.utils.statics.FunctionUtils;
import com.sxbbc.common.core.utils.FileUtils;
import com.sxbbc.common.core.utils.MultipartFileToFile;
import com.sxbbc.plat.common.MappingUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;

@Controller
public class FileController {


    /**
     * 文件上传:返回完整路径
     * @param file
     * @return
     */
    @CrossOrigin
    @RequestMapping(value = "/file/uploads", method = RequestMethod.POST)
    @ResponseBody
    public RestResponse fileUploads(MultipartFile file){
        try {
            File fe= MultipartFileToFile.multipartFileToFile(file);
            String path=FileUtils.up(fe);
             return new RestResponse("200",path,null);
        }catch (Exception e){
           return  null;
        }
    }



    @RequestMapping(value ="/file/editorupload")
    @ResponseBody
    public Object uploadFile(@Param("uploadImage") MultipartFile upfile){
       try {
           JSONObject json = new JSONObject();
           File fe= MultipartFileToFile.multipartFileToFile(upfile);
           String path=FileUtils.up(fe);
           json.put("state", "SUCCESS");
           json.put("url",path);
           json.put("size", null);
           json.put("original", null);
           json.put("title", null);
           json.put("type", null);
           return json;
       }catch (Exception e){
           return  null;
       }
    }



}
